package com.tmxk.rbac.test;

import com.tmxk.rbac.dao.SysDeptMapper;
import com.tmxk.rbac.pojo.SysDept;
import com.tmxk.rbac.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.util.List;

public class SysDeptMapperTest01 {
    @Test
    public void queryAllSysDeptTest(){
        //创建SqlSession会话
        SqlSession session = MyBatisUtils.createSqlSession(false);
        //基于Mapper接口映射调用查询方法
        SysDeptMapper sysDeptMapper = session.getMapper(SysDeptMapper.class);
        List<SysDept> sysDepts = sysDeptMapper.queryAllSysDept();
        sysDepts.forEach(dept->{
            System.out.println(dept.getDeptId() + "\t" + dept.getDeptName());
        });
    }

    @Test
    public void insertSysDeptTest(){
        //创建SqlSession会话
        SqlSession session = MyBatisUtils.createSqlSession(true);
        SysDeptMapper sysDeptMapper = session.getMapper(SysDeptMapper.class);
        SysDept dept = new SysDept();
        dept.setDeptId(101);
        dept.setDeptName("天马--运维部");
        int saveRes = sysDeptMapper.insertSysDept(dept);
        System.out.println("saveRes:" + saveRes);
    }

    @Test
    public void updateSysDeptTest(){
        //创建SqlSession会话
        SqlSession session = MyBatisUtils.createSqlSession(true);
        SysDeptMapper sysDeptMapper = session.getMapper(SysDeptMapper.class);
        SysDept dept = new SysDept();
        dept.setDeptId(101);
        dept.setDeptName("天马--运维部03");
     //   dept.setPhone("025-8740001");
        int updateRes = sysDeptMapper.updateSysDept(dept);
        System.out.println("updateRes:" + updateRes);
    }

    @Test
    public void deleteSysDeptTest(){
        //创建SqlSession会话
        SqlSession session = MyBatisUtils.createSqlSession(true);
        SysDeptMapper sysDeptMapper = session.getMapper(SysDeptMapper.class);
        SysDept dept = new SysDept();
        dept.setDeptId(101);
        dept.setDeptName("天马--运维部");
        int saveRes = sysDeptMapper.insertSysDept(dept);
        System.out.println("saveRes:" + saveRes);
    }

    @Test
    public void querySysDeptTest(){
        //创建SqlSession会话
        SqlSession session = MyBatisUtils.createSqlSession(false);
        //基于Mapper接口映射调用查询方法
        SysDeptMapper sysDeptMapper = session.getMapper(SysDeptMapper.class);
        System.out.println(sysDeptMapper.querySysDept(100));
    }
}
